﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entities;
namespace WCF_ListenMusic.Services.Module_Singer.Admin
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ManageSingerService" in code, svc and config file together.
    public class ManageSingerService : IManageSingerService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        public List<CountrySinger> getAllCountrySinger()
        {
            try {
                var q = from a in context.CountrySingers
                        select a;
                return q.ToList();
            }
            catch (Exception e) { throw new FaultException(e.Message); }
        }

        public bool deleteSinger_bySingerID(int singerid)
        {
            try
            {
                var q = from a in context.Singers
                        where a.SingerID.Equals(singerid)
                        select a;
                Singer s = q.Single();
                context.Singers.DeleteOnSubmit(s);
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { return false;  throw new FaultException(e.Message); }
        }

        public bool insertnewSinger(Entities.Singer singer)
        {
            try
            {
                context.Singers.InsertOnSubmit(singer);
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { return false; throw new FaultException(e.Message); }
        }

        public bool updateSinger(Entities.Singer singer)
        {
            try
            {
                var q = from a in context.Singers
                        where a.SingerID.Equals(singer.SingerID)
                        select a;
                Singer s = q.Single();
                s.SingerName = singer.SingerName;
                s.CountryID = singer.CountryID;
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { throw new FaultException(e.Message); }
        }


        public bool changeDisplay(int singerid)
        {
            try
            {
                var q = from a in context.Singers
                        where a.SingerID.Equals(singerid)
                        select a;
                Singer s = q.Single();
                if (s.Display == true)                
                    s.Display = false;                
                else
                    s.Display = true;                
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { throw new FaultException(e.Message); }
        }
    }
}
